/*
*  Copyright 2019-2023 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.service.impl;

import me.zhengjie.modules.system.domain.Pluginsclassify;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.system.service.PluginsclassifyService;
import me.zhengjie.modules.system.domain.vo.PluginsclassifyQueryCriteria;
import me.zhengjie.modules.system.mapper.PluginsclassifyMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author shitou
* @date 2024-04-22
**/
@Service
@RequiredArgsConstructor
public class PluginsclassifyServiceImpl extends ServiceImpl<PluginsclassifyMapper, Pluginsclassify> implements PluginsclassifyService {

    private final PluginsclassifyMapper pluginsclassifyMapper;


    @Override
    public PageResult<Pluginsclassify> queryAll(PluginsclassifyQueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(pluginsclassifyMapper.findAll(criteria, page));
    }

    @Override
    public List<Pluginsclassify> queryAll(PluginsclassifyQueryCriteria criteria){
        return pluginsclassifyMapper.findAll(criteria);
    }

    @Override
    public List<Pluginsclassify> queryRootpluginclassify(Integer  pluginsclassifyid ) {
        return pluginsclassifyMapper.queryRootpluginclassify(String.valueOf(pluginsclassifyid));
    }

    @Override
    public List<Pluginsclassify> queryplugin(Integer id) {
        return pluginsclassifyMapper.queryplugin(String.valueOf(id));
    }


    @Override
    public List<Pluginsclassify> queryRootpluginclassify(PluginsclassifyQueryCriteria criteria){
        return pluginsclassifyMapper.findAll(criteria);
    }



    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(Pluginsclassify resources) {
        save(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(Pluginsclassify resources) {
        Pluginsclassify pluginsclassify = getById(resources.getId());
        pluginsclassify.copy(resources);
        saveOrUpdate(pluginsclassify);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<Integer> ids) {
        removeBatchByIds(ids);
    }

    @Override
    public void download(List<Pluginsclassify> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (Pluginsclassify pluginsclassify : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("名称", pluginsclassify.getName());
            map.put("根id", pluginsclassify.getRootid());
            map.put("组件分类d", pluginsclassify.getPluginsclassifyid());
            map.put("排序", pluginsclassify.getOrderby());
            map.put("图标", pluginsclassify.getIcon());
            map.put("状态", pluginsclassify.getState());
            map.put("发布者", pluginsclassify.getUserid());
            map.put("发布时间", pluginsclassify.getCreatetime());
            map.put("操作时间", pluginsclassify.getLastupdatetime());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }

    @Override
    public List<Pluginsclassify> findById(Integer pluginsClassifyId) {
        return pluginsclassifyMapper.findById(String.valueOf(pluginsClassifyId));
    }
}